Image processing method and device

ABSTRACT

The present disclosure discloses an image processing method and device. The image processing method includes: dividing a detection image into a plurality of first subregions, dividing a template image into a plurality of second subregions, calculating a principal rotation direction of each first subregion with respect to the corresponding second subregion; and calculating a principal rotation direction of the detection image according to the principal rotation directions of the plurality of first subregions.

CROSS-REFERENCE TO RELATED APPLICATION

This application claims priority to Chinese Patent Application No.201710778512.4 filed on Sep. 1, 2017, which is incorporated herein byreference in its entirety.

TECHNICAL FIELD

The present disclosure relates to a field of image processingtechnologies, in particular to an image processing method and device.

BACKGROUND

In detection of a target image, template matching is commonly adopted,e.g., feature extraction and matching is performed on the target imageto be detected with a template. However, in practice, a pose of thetarget image to be detected tends to be different from that of atemplate image to some extent. For example, the target image is rotatedby a certain angle with respect to the template image. Therefore, it isnecessary for a detection algorithm to have a relatively strongrotational invariance, and a direction of the target image is adjustedby determining a rotation angle of the target image; afterwards, thefeature extraction and matching is performed on the target image.However, the detection algorithm is relatively complicated, and theimage identification has a relatively low reliability.

SUMMARY

The present disclosure provides an image processing method and device,so as to provide a method for acquiring a principal rotation directionof a detection image with respect to a template image.

In one aspect, some embodiments of the present disclosure provides animage processing method, including: dividing a detection image into aplurality of first subregions, and dividing a template image into aplurality of second subregions, wherein a center of each of theplurality of first subregions coincides with a center of the detectionimage, a center of each of the plurality of second subregions coincideswith a center of the template image, and the plurality of firstsubregions is in one-to-one correspondence to the plurality of secondsubregions; calculating a principal rotation direction of each of theplurality of first subregions with respect to corresponding secondsubregion, wherein the principal rotation direction of the firstsubregion with respect to the corresponding second subregion is anaverage value of sums of difference values of Δp of all pixel points pon an outer contour line of the first subregion and Δp′ of correspondingpixel points p′ on an outer contour line of the corresponding secondsubregion, Δp is an angle between a radial direction and a gradientdirection of each pixel point p, and Δp′ is an angle between a radialdirection and a gradient direction of each pixel point p′; andcalculating a principal rotation direction α of the detection imageaccording to the principal rotation directions of the plurality of firstsubregions of the detection image.

Optionally, the calculating the principal rotation direction α of thedetection image according to the principal rotation directions of theplurality of first subregions of the detection image includes: step S1of setting i=1; step S2 of comparing α_(i) with α_(i+1), and adjustingthe principal rotation direction of the detection image using anequation:

$\alpha = {{arc}\mspace{14mu} \tan \mspace{14mu} \left( \frac{\sum_{u = 1}^{u = {i + 1}}{\sin \mspace{14mu} \alpha_{u}}}{\sum_{u = 1}^{u = {i + 1}}{\cos \mspace{14mu} \alpha_{u}}} \right)}$

in the case that |α_(i)−α_(i+1)|≤ω, wherein u≤n, u is a positiveinteger, and α_(i) represents the principal rotation direction of ani^(th) first subregion of the plurality of first subregions; step S3 ofassigning i=i+1; and in the case that i is less than n, repeating stepsS2 and S3, wherein n represents the number of the plurality of firstsubregions.

Optionally, before the step S1, the image processing method furtherincludes: sorting the principal rotation directions of the plurality offirst subregions such that α_(i)>α_(i+1).

Optionally, ω=45°.

Optionally, before the step of calculating a principal rotationdirection of each of the plurality of first subregions with respect tocorresponding second subregion, the image processing method furtherincludes: selecting a circular region with one pixel point p on an outercontour line of each of the first subregions as a center of the circularregion, dividing the circular region into v concentric circles with thepixel point p as a center of the circles, and equally dividing thecircular region into w sector regions with the pixel point p as a vertexof the sector regions, to obtain v*w third subregions, wherein v and ware positive integers greater than or equal to 2; calculating a sum θ ofgradient directions of all the pixel points in each of the thirdsubregions; calculating a gradient direction θ_(p) of the pixel point p,wherein θ_(p) is a sum of products of θ of all the third subregions andcorresponding assigned weights ε, and ε is directly proportional to adistance between a central point of the third subregion and the pixelpoint p.

Optionally, the dividing the circular region into v concentric circleswith the pixel point p as a center of the circles, and equally dividingthe circular region into w sector regions with the pixel point p as avertex of the sector regions, to obtain v*w third subregions includes:dividing the circular region into two concentric circles with the pixelpoint p as the center of the circles, and dividing the circular regioninto 8 sector regions with the pixel point p as the vertex of the sectorregions, to obtain 16 third subregions.

Optionally, before the step of calculating a principal rotationdirection of each of the plurality of first subregions with respect tocorresponding second subregion, the image processing method furtherincludes: selecting a circular region with one pixel point p′ on anouter contour line of each of the second subregions as a center of thecircular region, dividing the circular region into v concentric circleswith the pixel point p′ as a center of the circles, and equally dividingthe circular region into w sector regions with the pixel point p′ as avertex of the sector regions, to obtain v*w fourth subregions;calculating a sum θ′ of gradient directions of all the pixel points ineach of the fourth subregions; and calculating a gradient directionθ_(p)′ of the pixel point p′, wherein θ_(p)′ is a sum of products of θ′of all the fourth subregions and corresponding assigned weights ε′, ε′is directly proportional to a distance between a central point of thefourth subregion and the pixel point p′, and v and w are positiveintegers greater than or equal to 2.

Optionally, the detection image is a circular region; the dividing thedetection image into a plurality of first subregions includes: defininga region where a distance from the center of the detection image is lessthan r_(i) and greater than r_(i−1) as the i^(th) first subregion of theplurality of first subregions, wherein r_(i−1)<r_(i), r₀=0, i is apositive integer and runs from 1 to n, and n represents the number ofthe first subregions; the dividing the template image into a pluralityof second subregions includes: defining a region where a distance fromthe center of the template image is less than r_(i) and greater thanr_(i−1) as the i^(th) second subregion of the plurality of secondsubregions, wherein r_(i−1)<r_(i), r₀≥0, i is a positive integer andruns from 1 to n, and n represents the number of the second subregions;and the calculating a principal rotation direction of each of theplurality of first subregions of the detection image with respect tocorresponding second subregion includes: determining the principalrotation direction of the detection image with a radius of r_(i) withrespect to the template image with a radius of r_(i) as the principalrotation direction α_(i) of the i^(th) first subregion with respect tothe corresponding second subregion.

Optionally, before the step of calculating a principal rotationdirection of each of the plurality of first subregions with respect tocorresponding second subregion, the image processing method furtherincludes: establishing a coordinate system with a center of thedetection image as an origin; calculating a radial direction φ_(p) ofone pixel point p on an outer contour line of each of the firstsubregions using an equation

${\phi_{p} = {{arc}\mspace{14mu} \tan \frac{\Delta \; p_{y}}{\Delta \; p_{x}}}},$

wherein (Δp_(x), Δp_(y)) is coordinates of the pixel point p, and0≤φ_(p)<2π.

Optionally, before the step of calculating a principal rotationdirection of each of the plurality of first subregions with respect tocorresponding second subregion, the image processing method furtherincludes: establishing a coordinate system with a center of the templateimage as an origin; calculating a radial direction φ_(p)′ of one pixelpoint p′ on an outer contour line of each of the second subregions usingan equation

${\phi_{p}^{\prime} = {{arc}\mspace{14mu} \tan \frac{\Delta \; p_{y}^{\prime}}{\Delta \; p_{x}^{\prime}}}},$

wherein (Δp_(x)′, Δp_(y)′) is coordinates of the pixel point p′, and0≤φ_(p)′<2π.

In another aspect, some embodiments of the present disclosure providesan image processing device, including: a processor and a memory, whereinthe processor is configured to execute a program stored in the memory,so as to: divide a detection image into a plurality of first subregions,and divide a template image into a plurality of second subregions,wherein a center of each of the plurality of first subregions coincideswith a center of the detection image, a center of each of the pluralityof second subregions coincides with a center of the template image, andthe plurality of first subregions is in one-to-one correspondence to theplurality of second subregions; calculate a principal rotation directionof each of the plurality of first subregions with respect tocorresponding second subregion, wherein the principal rotation directionof the first subregion with respect to the corresponding secondsubregion is an average value of sums of difference values of Δp of allpixel points p on an outer contour line of the first subregion and Δp′of corresponding pixel points p′ on an outer contour line of thecorresponding second subregion, Δp is an angle between a radialdirection and a gradient direction of each pixel point p, and Δp′ is anangle between a radial direction and a gradient direction of each pixelpoint p′; and calculate a principal rotation direction α of thedetection image according to the principal rotation directions of theplurality of first subregions of the detection image.

Optionally, the processor is further configured to execute followingsteps: step S1 of setting i=1; step S2 of comparing α_(i) with α_(i+1),and adjusting the principal rotation direction of the detection imageusing an equation:

$\alpha = {\arctan \; {\quad\left( \frac{\sum\limits_{u = 1}^{u = {i + 1}}{\sin \; \alpha_{u}}}{\sum\limits_{u = 1}^{u = {i + 1}}{\cos \; \alpha_{u}}} \right)}}$

in the case that |α_(i)−α_(i+1)|≤ω, wherein u≤n, u is a positiveinteger, and α_(i) represents the principal rotation direction of ani^(th) first subregion of the plurality of first subregions; step S3 ofassigning i=i+1; and in the case that i is less than n, repeating stepsS2 and S3, wherein n represents the number of the plurality of firstsubregions.

Optionally, the processor is further configured to, before the step S1,sort the principal rotation directions of the plurality of firstsubregions such that α_(i)>α_(i+1.)

Optionally, ω=45°.

Optionally, the processor is further configured to: select a circularregion with one pixel point p on an outer contour line of each of thefirst subregions as a center of the circular region, divide the circularregion into v concentric circles with the pixel point p as a center ofthe circles, and equally divide the circular region into w sectorregions with the pixel point p as a vertex of the sector regions, toobtain v*w third subregions, wherein v and w are positive integersgreater than or equal to 2; calculate a sum θ of gradient directions ofall the pixel points in each of the third subregions; and calculate agradient direction θ_(p) of the pixel point p, wherein θ_(p) is a sum ofproducts of θ of all the third subregions and corresponding assignedweights c, and c is directly proportional to a distance between acentral point of the third subregion and the pixel point p.

Optionally, the processor is further configured to divide the circularregion into two concentric circles with the pixel point p as the centerof the circles, and divide the circular region into 8 sector regionswith the pixel point p as the vertex of the sector regions, to obtain 16third subregions.

Optionally, the processor is further configured to: select a circularregion with one pixel point p′ on an outer contour line of each of thesecond subregions as a center of the circular region, divide thecircular region into v concentric circles with the pixel point p′ as acenter of the circles, and equally divide the circular region into wsector regions with the pixel point p′ as a vertex of the sectorregions, to obtain v*w fourth subregions; calculate a sum θ′ of gradientdirections of all the pixel points in each of the fourth subregions; andcalculate a gradient direction θ_(p)′ of the pixel point p′, whereinθ_(p)′ is a sum of products of θ′ of all the fourth subregions andrespective corresponding assigned weights ε′, ε′ is directlyproportional to a distance between a central point of the fourthsubregion and the pixel point p′, and v and w are positive integersgreater than or equal to 2.

Optionally, the detection image is a circular region, and the processoris further configured to: define a region where a distance from thecenter of the detection image is less than r_(i) and greater thanr_(i−1) as the i^(th) first subregion of the plurality of firstsubregions, wherein r_(i−1)<r_(i), r₀=0, i is a positive integer andruns from 1 to n, and n represents the number of the first subregions;define a region where a distance from the center of the template imageis less than r_(i) and greater than r_(i−1) as the i^(th) secondsubregion of the plurality of second subregions, wherein r_(i−1)<r_(i),r₀≥0, i is a positive integer and runs from 1 to n, and n represents thenumber of the second subregions; and determine the principal rotationdirection of the detection image with a radius of r_(i) with respect tothe template image with a radius of r_(i) as the principal rotationdirection α_(i) of the i^(th) first subregion with respect to thecorresponding second subregion.

Optionally, the processor is further configured to: establish acoordinate system with a center of the detection image as an origin; andcalculate a radial direction of one pixel point p on an outer contourline of each of the first subregions using an equation

${\phi_{p} = {\arctan \; \frac{\Delta \; p_{y}}{\Delta \; p_{x}}}},$

wherein (Δp_(x), Δp_(y)) is coordinates of the pixel point p, and0≤φ_(p)<2π.

Optionally, the processor is further configured to: establish acoordinate system with a center of the template image as an origin;calculate a radial direction of one pixel point p′ on an outer contourline of each of the second subregions to using an equation

${\phi_{p}^{\prime} = {\arctan \; \frac{\Delta \; p_{y}^{\prime}}{\Delta \; p_{x}^{\prime}}}},$

wherein (Δp_(x)′, Δp_(y)′) is coordinates of the pixel point p′, and0≤φ_(p)′<2π.

BRIEF DESCRIPTION OF THE DRAWINGS

In order to more clearly describe the technical solutions of theembodiments of the present invention or the prior art, the drawings tobe used in the descriptions of the embodiments or the prior art arebriefly introduced as follows. Obviously, the following drawings justillustrate some embodiments of the present invention, and a personskilled in the art can obtain other drawings from these drawings withoutpaying any creative effort.

FIG. 1 represents a first schematic diagram of dividing a detectionimage into a plurality of first subregions according to some embodimentsof the present disclosure;

FIG. 2 represents a schematic diagram of dividing a circular region intoa plurality of third subregions with a pixel point p on an outer contourline of each of the first subregions as a center of the circular regionaccording to some embodiments of the present disclosure;

FIG. 3 represents a coordinate system including one pixel point p on anouter contour line of the first subregion of the detection image and onepixel point p′ on an outer contour line of the second subregion of thetemplate image according to some embodiments of the present disclosure;

FIG. 4 represents a second schematic diagram of a detection image into aplurality of first subregions according to some embodiments of thepresent disclosure;

FIG. 5 represents a third schematic diagram of dividing a detectionimage into a plurality of first subregions according to some embodimentsof the present disclosure;

FIG. 6 represents a fourth schematic diagram of dividing a detectionimage into a plurality of first subregions according to some embodimentsof the present disclosure;

FIG. 7 represents a fifth schematic diagram of dividing a detectionimage into a plurality of first subregions according to some embodimentsof the present disclosure;

FIG. 8 is a flowchart showing a method for acquiring a principalrotation direction of a detection image with respect to a template imageaccording to some embodiments of the present disclosure.

DETAILED DESCRIPTION

The present disclosure is below further described in detail incombination with drawings and specific embodiments. The followingembodiments are used for explaining the present disclosure, but not tolimit the scope thereof.

The present embodiment provides an image processing method for acquiringa detection image, and matching the detection image with a templateimage, so as to perform identification detection on the target. Thedetection image may be an image of the entire target, or a part of thetarget image.

The image processing method includes the steps of a method for obtaininga principal rotation direction of an image, so as to acquire theprincipal rotation direction of the detection image with respect to thetemplate image, and the principal direction of rotation includes arotation angle and a rotation direction. In the image processing method,firstly, the detection image is rotated according to the principalrotation direction, so that a pose of the detection image is the same asthat of the template image, without a rotation angle, then the featureextraction and matching is performed on the rotated detection image andtemplate image, so as to realize the identification detection of thetarget. Since the rotated detection image has the same pose as thetemplate image, without a rotation angle, the subsequent imageidentification processing algorithm may not have the rotationinvariance, which simplifies the image identification processingalgorithm and improves the reliability of the image identificationdetection.

The steps of the method for acquiring a principal direction of rotationof the image include: acquiring a principal rotation direction of thedetection image with respect to the template image.

Exemplarily, as shown in FIG. 8, the acquiring the principal rotationdirection of the detection image with respect to the template imageincludes the following steps.

According to a same preset rule, the detection image is divided into aplurality of first subregions, and the template image is divided into aplurality of second subregions, wherein a center of each of theplurality of first subregions coincides with a center of the detectionimage, and a center of each of the plurality of second subregionscoincides with a center of the template image.

A principal rotation direction of each of the plurality of firstsubregions with respect to the corresponding second subregion iscalculated. The principal rotation direction of the first subregion withrespect to the corresponding second subregion is an average value ofsums of difference values of Δp of all pixel points p on an outercontour line of the first subregion and Δp′ of corresponding pixelpoints p′ on an outer contour line of the corresponding secondsubregion, wherein Δp is an angle between a radial direction and agradient direction of each pixel point p, and Δp′ is an angle between aradial direction and a gradient direction of each pixel point p′. Theprincipal rotation direction α of the detection image is calculatedaccording to the principal rotation directions of all first subregionsof the detection image.

Optionally, the centers of the plurality of first subregions are thesame, the centers of the plurality of second subregions are the same,and the plurality of first subregions is in one-to-one correspondence tothe plurality of second subregions. Optionally, any one of the firstsubregions has the same shape and size as its corresponding secondsubregion.

In the above-mentioned image processing method, firstly, the detectionimage and the template image are divided into a plurality of subregionsaccording to the same rule, a principal rotation direction of each ofthe plurality of first subregions of the detection image with respect tothe corresponding subregion of the template image is calculated, andthen the principal rotation direction of the detection image iscalculated according to the principal rotation directions of all thesubregions of the detection image, wherein the principal rotationdirection of each subregion of the detection image with respect to thecorresponding subregion of the template image is an average value ofsums of difference values of an angle between the radial direction andthe gradient direction of each of all pixel points on an outer contourline of each of the subregions of the detection image and an anglebetween the radial direction and the gradient direction of thecorresponding pixel point on an outer contour line of the correspondingsubregion of the template image. By adopting the angle between theradial direction and the gradient direction of the pixel point, theprincipal rotation direction of the image is acquired, with a relativelyhigh accuracy and precision. By rotating the detection image in theprincipal rotation direction, the detection image has the same pose asthe template image, without a rotation angle, so the subsequent imageidentification processing algorithm may not have the rotationinvariance, which simplifies the image identification processingalgorithm and improves the reliability of the image identificationdetection.

The principal rotation direction of each of the first subregions of thedetection image with respect to the corresponding second subregion ofthe template image may be positive or negative, and the acquiredprincipal rotation direction α of the detection image may also bepositive or negative, so as to represent the counterclockwise rotationor clockwise rotation of the detection image with respect to thetemplate image. In the case that a is set to be positive, the detectionimage counterclockwise rotates with respect to the template image;whereas in the case that a is negative, the detection image clockwiserotates with respect to the template image.

In the present embodiment, the step of dividing the detection image andthe template image into a plurality of subregions according to the samepreset rule means that all the subregions of the detection image and thetemplate image have the same shape and size, a center of each of theplurality of first subregions coincides with a center of the detectionimage; and a center of each of the plurality of second subregionscoincides with a center of the template image.

As shown in FIGS. 1, and 4-7, taking the detection image as an example,the division of the detection image into a plurality of subregionsaccording to the preset rule means that the center of the detectionimage is taken as a center of each of the plurality of subregions (forexample, the center of each subregion coincides with the center of thedetection image), and the detection image is divided into a plurality ofsubregions using a plurality of graphics which are the same, not exactlythe same or totally different. It should be noted that the same anddifferent graphics herein only refers to their shapes. For the sake ofconvenient description, in Figures, four subregions are describedschematically. It should be understood that the number of subregions isnot limited in the embodiment of the present disclosure, and thedetection image may also be divided into two or more than twosubregions.

As shown in FIG. 1, the detection image 100 is divided into a pluralityof concentric first subregions, wherein the first subregion 101-1 is acircular region, and other first subregions (for example, firstsubregions 101-2, 101-3 and 101-4) are circular ring-shaped regions. Asshown in FIG. 4, the detection image 400 is divided into a plurality ofconcentric first subregions, wherein one first subregion (e.g., thefirst subregion 401-1) is a rectangular region, and other firstsubregions (for example, first subregions 401-2, 401-3 and 401-4) arerectangular ring-shaped regions. It should be understood that a boundaryline of two adjacent first subregions and a boundary line surroundingall the first subregions may be circular, rectangular or of other shapes(for example, an oval).

Certainly, different boundary lines may have the same or differentshapes. For example, as shown in FIG. 5, the detection image 500 is acircular region, and is divided into a plurality of concentric firstsubregions, wherein the boundary line between the first subregion 501-1and the first subregion 501-2 as well as the boundary line surroundingthe first subregions 501-1, 501-2, 501-3 and 501-4 are circular, and theboundary line between the first subregion 501-2 and the first subregion501-3 as well as the boundary line between the first subregion 501-3 andthe first subregion 501-4 are rectangular.

In other words, the boundary lines of the first subregions away from thecenter of the detection image may have the same shape (for example,circle, rectangle, oval, or the like) or different shapes, or a part ofthe boundary lines has the same shape. It should be further noted thatthe shape of each boundary line, the size of each subregion and thepositional relationship between subregions may be adjusted as needed,and are not limited thereto.

It should be noted that since the template image and the detection imageare divided into a plurality of subregions according to the same presetrule, only the division rule of the detection image is shown in Figures,and the division rule of the template image is not illustratedrepeatedly.

Optionally, as shown in FIG. 1, the detection image 100 is set to be acircular region, and the detection image 100 may be divided into aplurality of concentric first subregions, wherein one first subregion101-1 is a circular region, and other first subregions (for example,first subregions 101-2, 101-3 and 101-4) are circular ring-shapedregions. The circular region and circular ring-shaped regions haveunchanged pixels before and after rotation, which may further improvethe accuracy of the acquired principal direction of rotation of theimage.

In some embodiments, the step of dividing the detection image into aplurality of first subregions according to the same preset rule is asbelow.

The detection image is divided into n first subregions by using nconcentric circles with radii different from each other, and the centersof the n concentric circles of the detection image coincide with thecenter of the detection image. Optionally, the i^(th) concentric circleof the n concentric circles has a radius of r_(i), wherein i≤n, i is apositive integer, r_(i−1)<r_(i), and r₀≥0. One of the first subregionsof the detection image is a circular region with a radius of r₁, and anyone of other first subregions is a circular ring-shaped region betweentwo adjacent circular regions. To be specific, the concentric circlewith a radius of r₁ defines the first one of the n first subregions,that is, a circular region with a radius of r₁; the circular ring-shapedregion between the j^(th) circle and the (j+1)^(th) circle defines the(j+1)^(th) first subregion of the n first subregions, wherein j is apositive integer and runs from 1 to n−1, and n is an integer greaterthan or equal to 2. In other words, the region with a radius less thanr_(i) and greater than r_(i−1) is defined as the i^(th) subregion of then first subregions, wherein the value of i runs from 1 to n, and r₀=0.

In some embodiments, the step of dividing the corresponding templateimage into a plurality of second subregions is as below.

The template image is divided into n second subregions by using nconcentric circles with radii different from each other, the centers ofthe n concentric circles of the template image coincide with the centerof the template image, one of the second subregions of the templateimage is a circular region with a radius of r₁, and any one of othersecond subregions is a circular ring-shaped region between two adjacentcircles of the n concentric circles, wherein the smallest circle of then concentric circles has a radius of r₁. The way of dividing thetemplate image into a plurality of second subregions is similar to thatof dividing the detection image into a plurality of first subregions, soit can refer to the above-mentioned contents, and is not repeatedherein.

Correspondingly, the step of calculating the principal rotationdirection α_(i) of the i^(th) first subregion of the detection imagewith respect to the second subregion corresponding to the firstsubregion is as below.

The principal rotation direction α_(i) of the circle with a radius ofr_(i) of the detection image with respect to the circle with a radius ofr_(i) of the template image is calculated. In the case that the firstsubregion is a circular region, the circle corresponding to the firstsubregion has a radius of r₁. In the case that the first subregion is acircular ring-shaped region, the circle corresponding to the firstsubregion has a relatively large radius.

In the above-mentioned step, the detection image is a circular region,and the detection image and the template image are divided into aplurality of subregions by a plurality of concentric circles.

Further, the radii of the plurality of concentric circles can be alsoset to increase progressively in an arithmetic progression, that is,r_(i)−r_(i−1)=d (d=r_(n)/n, r₀=0), so that the plurality of firstsubregions is distributed evenly, and the accuracy of the acquiredprincipal rotation direction of the image can be further improved.

In the present embodiment, the calculating the principal rotationdirection of the detection image according to the principal rotationdirections of all first subregions of the detection image includesfollowing steps: step S1 of setting that i=1; step S2 of comparing α_(i)with α_(i+1), and adjusting the principal direction of rotation of thedetection image

$\alpha = {\arctan \; {\quad\left( \frac{\sum\limits_{u = 1}^{u = {i + 1}}{\sin \; \alpha_{u}}}{\sum\limits_{u = 1}^{u = {i + 1}}{\cos \; \alpha_{u}}} \right)}}$

in the case that |α_(i)−α_(i+1)|≤ω, wherein u≤n, and u is a positiveinteger; step S3 of assigning i=i+1; and repeating steps S2 and S3 inthe case that i is less than n.

In the above-mentioned steps, the principal rotation directions of allthe subregions are sorted firstly, so as to form a sequence of α₁, α₂,α₃, . . . α_(n), then the initial principal rotation direction of thedetection image is set to be α₁, and the principal rotation directionsof all the subregions are traversed in sequence. In the case that theangle of the principal rotation direction of the next subregion withrespect to the former subregion is not greater than ω, it is consideredthat the principal rotation direction of the next subregion is valid,and the principal rotation direction of the detection image is adjustedaccording to the above-mentioned formula. In the case that the angle ofthe principal rotation direction of the next subregion with respect tothe former subregion is greater than ω, it is considered that theprincipal rotation direction of the next subregion is invalid, and theprincipal rotation direction of the detection image is not adjusted.

In some embodiments, ω is set according to a change in a reasonable poseof the target. Usually, it is set that 0°≤ω≤60°, which can satisfy thedemand of identification detection of most of the targets. Preferably,it is set that ω=45°.

To be specific, before the step S1, the principal rotation directions ofall the subregions are sorted, and subsequent to sorting, α_(i)>α_(i+1),such that the principal rotation directions of all the subregions aresorted from large to small, so as to form a sequence of α₁, α₂, α₃, . .. α_(n).

Certainly, the rule of sorting the principal rotation directions of allthe subregions is not limited thereto. For example, the principalrotation directions of all the subregions can be sorted from small tolarge, or sorted according to a distance of the subregion from thecenter of the detection image, and its sorting manner is not enumeratedherein.

The principal rotation direction of the image is acquired by adoptingthe angle between the radial direction and the gradient direction of thepixel point. Therefore, it needs to calculate the radial direction andthe gradient direction of the pixel point.

To be specific, as shown in FIG. 2, the step of calculating the gradientdirection θ_(p) of one pixel point p on the outer contour line of eachof the first subregions of the detection image includes: selecting acircular region with the pixel point p as a center of the circularregion, dividing the circular region into v concentric circles with thepixel point p as a center of the circles, and equally dividing thecircular region into w sector regions with the pixel point p as a vertexof the sector regions, to obtain v*w third subregions 102; calculating asum θ of gradient directions of all the pixel points in each of thethird subregions 102; and calculating a gradient direction θ_(p) of thepixel point p, wherein θ_(p) is a sum of products of θ of all the thirdsubregions 102 and corresponding assigned weights ε, and ε is directlyproportional to a distance between a central point of the thirdsubregion 102 and the pixel point p.

Since the pixels of the circular region before and after the imagerotation keep constant, in the above-mentioned steps, the gradientdirection of this point is calculated for each pixel point p on theouter contour line of the first subregion by using a circular localneighborhood, and the gradient direction of each of the pixel points pcan be acquired accurately.

To be specific, the circular region may be divided into two concentriccircles with the pixel point p as a center of the circles, and thecircular region is equally divided into 8 sector regions with the pixelpoint p as the vertex of the sector regions, thereby dividing thecircular region into 16 third subregions 102.

In the present disclosure, since the detection image and the templateimage are divided into a plurality of subregions according to the samepreset rule, the above-mentioned method may be also used to calculatethe gradient direction θ_(p)′ of one pixel point p′ on the outer contourline of each of the second subregions of the template image.

To be specific, the step of calculating a gradient direction θ_(p)′ ofone pixel point p′ on an outer contour line of each of the secondsubregions of the template image includes: selecting a circular regionwith the pixel point p′ as a center of the circular region, dividing thecircular region into v concentric circles with the pixel point p′ as acenter of the circles, and equally dividing the circular region into wsector regions with the pixel point p′ as a vertex of the sectorregions, thereby dividing the circular region into v*w fourthsubregions; calculating a sum θ′ of gradient directions of all the pixelpoints p′ in each of the fourth subregions; and calculating a gradientdirection θ_(p)′ of the pixel point p′; wherein θ_(p)′ is a sum ofproducts of θ′ of all the fourth subregions and corresponding assignedweights ε′, and ε′ is directly proportional to a distance between acentral point of the fourth subregion and the pixel point p′.

In the foregoing, the gradient direction θ_(p) of one pixel point p onthe outer contour line of each of the first subregions of the detectionimage and the gradient direction θ_(p)′ of one pixel point p′ on theouter contour line of each of the second subregions of the templateimage are calculated by using the circular local neighborhood of thepixel point.

It should be noted that the gradient direction θ_(p) of one pixel pointp on the outer contour line of each of the first subregions of thedetection image and the gradient direction θ_(p)′ of one pixel point p′on the outer contour line of each of the second subregions of thetemplate image may be calculated by using a different method. Certainly,the method for calculating the gradient direction of the pixel point isnot limited to the above-mentioned method.

In the present embodiment, as shown in FIG. 3, the step of calculating aradial direction φ_(p) of one pixel point p on an outer contour line ofeach of the first subregions of the detection image includes:establishing a coordinate system xoy with a center of the detectionimage as an origin; and calculating a radial direction φ_(p) of onepixel point p on an outer contour line of each of the first subregionsusing an equation:

${\phi_{p} = {\arctan \; \frac{\Delta \; p_{y}}{\Delta \; p_{x}}}},$

wherein (Δp_(x), Δp_(y)) is coordinates of the pixel point p in thecoordinate system xoy, and 0≤φ_(p)<2π.

Similarly, the step of calculating a radial direction φ_(p)′ of onepixel point p′ on an outer contour line of each of the second subregionsof the template image includes: establishing a coordinate system x′o′y′with a center of the template image as an origin; and calculating aradial direction φ_(p)′ of one pixel point p′ on an outer contour lineof each of the second subregions using an equation:

${\phi_{p}^{\prime} = {\arctan \; \frac{\Delta \; p_{y}^{\prime}}{\Delta \; p_{x}^{\prime}}}},$

wherein (Δp′, Δp_(y)′) is coordinates of the pixel point p′ in thecoordinate system x′o′y′, and 0≤φ_(p)′<2π.

Since the detection image has the same shape and size as the templateimage, and the detection image and the template image are divided into aplurality of subregions according to the same preset rule, one pixelpoint p on the outer contour line of the first subregion of thedetection image and one pixel point p′ on the outer contour line of thecorresponding second subregion of the template image are shownschematically in FIG. 3, wherein the pixel point p corresponds to thepixel point p′ in position.

In FIG. 3, the outer contour lines of the first subregion of thedetection image and the second subregion of the template image arecircular. It should be noted that the outer contour lines of the firstsubregion of the detection image and the second subregion of thetemplate image may be also elliptic, rectangular, or the like.

In the present embodiment, the detection image is a circular region, andthe acquiring the principal rotation direction of the detection imagewith respect to the template image in the image processing methodincludes the following steps.

The detection image is divided into n first subregions by using nconcentric circles with radii different from each other, and the centersof the n concentric circles of the detection image coincide with thecenter of the detection image. Optionally, the ith concentric circle ofthe n concentric circles has a radius of r_(i), wherein i≤n, i is apositive integer, and r_(i)<r_(i+1). One of the first subregions of thedetection image is a circular region with a radius of r₁, and any one ofother first subregions is a circular ring-shaped region between twoadjacent circular regions.

The template image is divided into n second subregions by using nconcentric circles with radii different from each other, the centers ofthe n concentric circles of the template image coincide with the centerof the template image, one of the second subregions of the templateimage is a circular region with a radius of r₁, and any one of othersecond subregions is a circular ring-shaped region located between twoadjacent circles, wherein the smallest circle of the n concentriccircles has a radius of r₁.

The principal rotation direction α_(i) of the circle with a radius ofr_(i) corresponding to each of the first subregions with respect to thecircle with a radius of r_(i) of the template image is calculated. Inthe case that the first subregion is a circular region, the circlecorresponding to the first subregion has a radius of r₁. In the casethat the first subregion is a circular ring-shaped region, the circlecorresponding to the first subregion has a relatively large radius.α_(i) is an average value of sums of difference values of Δp of allpixel points p on an outer contour line of each first subregion of thedetection image and Δp′ of pixel points p′ on an outer contour line ofthe corresponding second subregion, wherein Δp is an angle between aradial direction and a gradient direction of each pixel point p, and Δp′is an angle between a radial direction and a gradient direction of eachpixel point p′.

The principal rotation directions of all the subregions are sorted, soas to form a sequence of α₁, α₂, α₃, . . . α_(n), wherein α_(i)>α_(i+1),and the initial principal rotation direction of the detection image isset to be a1.

The calculating the principal rotation direction of the detection imageaccording to the principal rotation directions of all first subregionsof the detection image includes: step S1 of setting that i=1; step S2 ofcomparing α_(i) with α_(i+1), and adjusting the principal direction ofrotation of the detection image using an equation:

$\alpha = {\arctan \; {\quad\left( \frac{\sum\limits_{u = 1}^{u = {i + 1}}{\sin \; \alpha_{u}}}{\sum\limits_{u = 1}^{u = {i + 1}}{\cos \; \alpha_{u}}} \right)}}$

in the case that |α_(i)−α_(i+1)|≤ω, wherein u≤n, and u is a positiveinteger; step S3 of assigning i=i+1; and repeating steps S2 and S3 inthe case that i is less than n.

So far, the principal rotation direction α of the detection image withrespect to the template image is acquired.

The gradient directions of the pixel point p on the outer contour lineof the first subregion and the pixel point p′ on the outer contour lineof the second subregion may be calculated by using the circular localneighborhood. The radial direction of the pixel point p on the outercontour line of the first subregion may be acquired by establishing acoordinate system with the center of the detection image as an origin.Similarly, the radial direction of the pixel point p′ on the outercontour line of the second subregion may be acquired by establishing acoordinate system with the center of the template image as an origin.The specific method has been described in the above, and is notdescribed in detail herein.

In the above-mentioned image processing method, the detection image isdivided into a plurality of first subregions by using a plurality ofconcentric circles, the template image is divided into a plurality ofsecond subregions according to the same rule. By acquiring the principalrotation direction of each of the first subregions with respect to thecorresponding second subregion, the principal rotation direction of theentire detection image with respect to the template image is acquired.Since the first subregion and the corresponding second subregion arecircular regions or circular ring-shaped regions, the pixels before andafter the image rotation keep constant, thereby improving the accuracyand precision of the acquired principal rotation direction.

In the above-mentioned image processing method, the sequential order ofthe steps is not defined, and can be reasonably adjusted as long as thetechnical solution of the present disclosure may be implemented.

In the present embodiment, an image processing device is provided,including an image rotation processing module, configured to acquire theprincipal rotation direction of the image. In the image processingdevice, firstly, the detection image is rotated according to theprincipal rotation direction, so that a pose of the detection image isthe same as that of the template image, without a rotation angle, andthen the feature extraction and matching are performed on the rotateddetection image and template image, so as to realize the identificationdetection of the target. Since the rotated detection image has the samepose as the template image, without a rotation angle, the subsequentimage identification processing algorithm may not have the rotationinvariance, which simplifies the image identification processingalgorithm and improves the reliability of the image identificationdetection.

The image rotation processing module includes an acquiring module,configured to acquire the principal rotation direction of the detectionimage with respect to the template image.

The acquiring module includes: a first dividing unit, a calculating unitand an acquiring unit.

The first dividing unit is configured to, according to the same presetrule, divide the detection image into a plurality of first subregions,and divide the template image into a plurality of second subregions,wherein the centers of the plurality of first subregions coincide withthe center of the detection image, and the centers of the plurality ofsecond subregions coincide with the center of the template image.

The calculating unit is configured to calculate a principal rotationdirection of each of the plurality of first subregions of the detectionimage with respect to the corresponding second subregion, wherein theprincipal rotation direction of the first subregion with respect to thecorresponding second subregion is an average value of sums of differencevalues of Δp of all pixel points p on an outer contour line of the firstsubregion and Δp′ of corresponding pixel points p′ on an outer contourline of the corresponding second subregion, Δp is an angle between aradial direction and a gradient direction of each pixel point p, and Δp′is an angle between a radial direction and a gradient direction of eachpixel point p′.

The acquiring unit is configured to calculate a principal rotationdirection α of the detection image according to the principal rotationdirections of the plurality of first subregions of the detection image.

In the above-mentioned image processing device, firstly, the detectionimage and the template image are divided into a plurality of subregionsaccording to the same rule, a principal rotation direction of each ofthe plurality of first subregions of the detection image with respect tothe corresponding subregion of the template image is calculated, andthen the principal rotation direction of the detection image iscalculated according to the principal rotation directions of all thesubregions of the detection image, wherein the principal rotationdirection of each subregion of the detection image with respect to thecorresponding subregion of the template image is an average value ofsums of difference values of an angle between the radial direction andthe gradient direction of each of all pixel points on an outer contourline of each of the subregions of the detection image and an anglebetween the radial direction and the gradient direction of thecorresponding pixel point on an outer contour line of the correspondingsubregion of the template image. By adopting the angle between theradial direction and the gradient direction of the pixel point, theprincipal rotation direction of the image is acquired, with a relativelyhigh accuracy and precision. By rotating the detection image in theprincipal rotation direction, the detection image has the same pose asthe template image, without a rotation angle, so the subsequent imageidentification processing algorithm may not have the rotationinvariance, which simplifies the image identification processingalgorithm and improves the reliability of the image identificationdetection.

Preferably, as shown in FIG. 1, the detection image 100 is set to be acircular region, and the detection image 100 is divided into a pluralityof first subregions 101 using a plurality of concentric circles, whereinone first subregion is a circular region, and other first subregions arecircular ring-shaped regions, and the pixels of the circular region andthe circular ring-shaped regions before and after the rotation keepconstant, which may further improve the precision of the acquiredprincipal direction of rotation of the image.

Correspondingly, the first dividing unit includes a first dividingsubunit and a second dividing subunit.

The first dividing subunit is configured to divide the detection imageinto n first subregions by using n concentric circles with radiidifferent from each other, wherein the centers of the n concentriccircles of the detection image coincide with the center of the detectionimage, the i^(th) concentric circle of the n concentric circles has aradius of r_(i), i is a positive integer and runs from 1 to n,r_(i−1)<r_(i), and r₀≥0. One of the first subregions of the detectionimage is a circular region with a radius of r₁, and any one of otherfirst subregions is a circular ring-shaped region between two adjacentcircular regions of the n concentric circles.

The second dividing subunit is configured to divide the template imageinto n second subregions by using n concentric circles with radiidifferent from each other; wherein the centers of the n concentriccircles of the template image coincide with the center of the templateimage, one of the second subregions of the template image is a circularregion with a radius of r₁, any one of other second subregions is acircular ring-shaped region located between two adjacent circles, andthe smallest circle of the n concentric circles has a radius of r₁.

The calculating unit is further configured to calculate the principalrotation direction α_(i) of the circle with a radius of r_(i)corresponding to each of the first subregions with respect to the circlewith a radius of r_(i) of the template image. In the case that the firstsubregion is a circular region, the circle corresponding to the firstsubregion has a radius of r₁. In the case that the first subregion is acircular ring-shaped region, the circle corresponding to the firstsubregion has a relatively large radius.

In the above image processing device, the detection image is set to bethe circular region, and the detection image and the template image aredivided into a plurality of subregions by a plurality of concentriccircles.

In the present disclosure, the principal rotation direction of the imageis acquired by adopting the angle between the radial direction and thegradient direction of the pixel point. Therefore, it needs to calculatethe radial direction and the gradient direction of the pixel point.

To be specific, the calculating unit includes a first calculating unitconfigured to calculate the gradient direction θ_(p) of one pixel pointp on each of the first subregions of the detection image.

The first calculating unit includes: a first selecting unit, configuredto select one circular region with a pixel point p as a center of thecircular region; a second dividing unit, configured to divide thecircular region into v concentric circles with the pixel point p as acenter of the circles, and equally divide the circular region into wsector regions with the pixel point p as a vertex of the sector regions,to obtain v*w third subregions; a first calculating subunit, configuredto calculate a sum θ of gradient directions of all the pixel points p ineach of the third subregions; and a second calculating subunit,configured to calculate a gradient direction θ_(p) of the pixel point p,wherein θ_(p) is a sum of products of θ of all the third subregions andcorresponding assigned weights c, and c is directly proportional to adistance between a central point of the third subregion and the pixelpoint p.

Since the pixels of the circular region before and after the imagerotation keep constant, in the above-mentioned steps, the gradientdirection of this point is calculated for each pixel point p on theouter contour line of the first subregion by using a circular localneighborhood, and the gradient direction of each of the pixel points pcan be acquired accurately.

In the present disclosure, since the detection image and the templateimage are divided into a plurality of subregions according to the samepreset rule, the above-mentioned method may be also used to calculatethe gradient direction θ_(p)′ of one pixel point p′ on the outer contourline of each of the second subregions of the template image.

To be specific, the calculating unit further includes a secondcalculating unit configured to calculate the gradient direction θ_(p)′of one pixel point p′ on each of the second subregions of the templateimage.

The second calculating unit includes: a second selecting unit,configured to select one circular region with a pixel point p′ as acenter of the circular region; a third dividing unit, configured todivide the circular region into v concentric circles with the pixelpoint p′ as a center of the circles, and equally divide the circularregion into w sector regions with the pixel point p′ as a vertex of thesector regions, to obtain v*w fourth subregions; a third calculatingsubunit, configured to calculate a sum θ′ of gradient directions of allthe pixel points p′ in each of the fourth subregions; and a fourthcalculating subunit, configured to calculate a gradient direction θ_(p)′of the pixel point p′, wherein θ_(p)′ is a sum of products of θ′ of allthe fourth subregions and respective corresponding assigned weights ε′,ε′ is directly proportional to a distance between a central point of thefourth subregion and the pixel point p′.

In the above-mentioned image processing device, the gradient directionθ_(p) of one pixel point p on the outer contour line of each of thefirst subregions of the detection image and the gradient directionθ_(p)′ of one pixel point p′ on the outer contour line of each of thesecond subregions of the template image are calculated by using acircular local neighborhood of the pixel point.

It should be noted that the gradient direction θ_(p) of one pixel pointp on the outer contour line of each of the first subregions of thedetection image and the gradient direction θ_(p)′ of one pixel point p′on the outer contour line of each of the second subregions of thetemplate image may be calculated by using a different method. Certainly,the method for calculating the gradient direction of the pixel point isnot limited to the above-mentioned method.

In the present embodiment, as shown in FIG. 3, the calculating unitfurther includes a third calculating unit, configured to calculate aradial direction φ_(p) of one pixel point p on an outer contour line ofeach of the first subregions of the detection image.

The third calculating unit includes: a first coordinate systemestablishing unit, configured to establish a coordinate system xoy witha center of the detection image as an origin; and a fifth calculatingsubunit, configured to calculate a radial direction of one pixel point pon an outer contour line of each of the first subregions using anequation

${\phi_{p} = {\arctan \; \frac{\Delta \; p_{y}}{\Delta \; p_{x}}}},$

wherein (Δp_(x), Δp_(y)) is a coordinate of the pixel point p in thecoordinate system xoy, and 0≤φ_(p)<2π.

Similarly, the calculating unit further includes a fourth calculatingunit, configured to calculate a radial direction φ_(p)′ of one pixelpoint p′ on an outer contour line of each of the second subregions ofthe template image.

The fourth calculating unit includes: a second coordinate systemestablishing unit, configured to establish a coordinate system x′o′y′with a center of the template image as a central point; and a sixthcalculating subunit, configured to calculate a radial direction of onepixel point p′ on an outer contour line of each of the second

subregions using an equation

${\phi_{p}^{\prime} = {\arctan \; \frac{\Delta \; p_{y}^{\prime}}{\Delta \; p_{x}^{\prime}}}},$

wherein (Δp_(x)′, Δp_(y)′) is a coordinate of the pixel point p′ in thecoordinate system x′o′y′, and 0≤φ_(p)′<2π.

In the present embodiment, the detection image is a circular region. Forthe image processing device, the acquiring module of its image rotationprocessing module includes a first dividing unit, a calculating unit andan acquiring unit.

The first dividing unit includes a first dividing subunit and a seconddividing subunit. The first subdividing unit is configured to divide thedetection image into n first subregions by using n concentric circleswith radii different from each other, and the centers of the nconcentric circles of the detection image coincide with the center ofthe detection image, wherein i≤n, i is a positive integer,r_(i−1)<r_(i), and r₀≥0. Optionally, one of the first subregions of thedetection image is a circular region with a radius of r₁, and any one ofother first subregions is a circular ring-shaped region located betweentwo adjacent circular regions. The second dividing subunit is configuredto divide the template image into n second subregions by using nconcentric circles with radii different from each other, and the centersof the n concentric circles of the template image coincide with thecenter of the template image. Optionally, one of the second subregionsof the template image is a circular region with a radius of r₁, and anyone of other second subregions is a circular ring-shaped region locatedbetween two adjacent circles.

The calculating unit is configured to calculate the principal rotationdirection of the circle with a radius of r_(i) of the detection imagewith respect to the circle with a radius of r_(i) of the template image,to be determined as the principal rotation direction α_(i) of the i^(th)first subregion with respect to the corresponding second subregion. Inthe case that the first subregion is a circular region, the circlecorresponding to the first subregion has a radius of r₁. In the casethat the first subregion is a circular ring-shaped region, the circlecorresponding to the first subregion has a relatively large radius.α_(i) is an average value of sums of difference values of Δp of allpixel points p on an outer contour line of each first subregion of thedetection image and Δp′ of corresponding pixel points p′ on an outercontour line of the second subregion corresponding to the firstsubregion, wherein Δp is an angle between a radial direction and agradient direction of each pixel point p, and Δp′ is an angle between aradial direction and a gradient direction of each pixel point p′.

The acquiring unit is configured to calculate the principal rotationdirection of the detection image according to the principal rotationdirections of all first subregions of the detection image.

The calculating unit may be configured to calculate the gradientdirections of the pixel points p on the outer contour line of the firstsubregion and the pixel points p′ on the outer contour line of thesecond subregion by using the circular local neighborhood. The radialdirection of each pixel point p on the outer contour line of the firstsubregion may be obtained by establishing a coordinate system with thecenter of the detection image as the origin. Similarly, the radialdirection of the pixel point p′ on the outer contour line of the secondsubregion may be obtained by establishing a coordinate system with thecenter of the template image as the origin. The specific implementationstructure has been described in the above, and is not described indetail herein

In the above-mentioned image processing device, the detection image isdivided into a plurality of first subregions by using a plurality ofconcentric circles, and the template image is divided into a pluralityof second subregions according to the same rule. By acquiring theprincipal rotation direction of each of the first subregions withrespect to the corresponding second subregion, the principal rotationdirection of the entire detection image with respect to the templateimage is acquired. Since the first subregion and the correspondingsecond subregion are circular regions or circular ring-shaped regions,the pixels before and after the image rotation keep constant, therebyimproving the accuracy and precision of the acquired principal directionof rotation.

The foregoing is merely to describe preferably embodiments of thepresent disclosure. It should be noted that several improvements andmodifications may be made for a person skilled in the art withoutdeparting from the technical principle of the present disclosure, andshould be also considered as the protection scope of the presentdisclosure.

What is claimed is:
 1. An image processing method, comprising: dividinga detection image into a plurality of first subregions, and dividing atemplate image into a plurality of second subregions, wherein a centerof each of the plurality of first subregions coincides with a center ofthe detection image, a center of each of the plurality of secondsubregions coincides with a center of the template image, and theplurality of first subregions is in one-to-one correspondence to theplurality of second subregions; calculating a principal rotationdirection of each of the plurality of first subregions with respect tocorresponding second subregion, wherein the principal rotation directionof the first subregion with respect to the corresponding secondsubregion is an average value of sums of difference values of Δp of allpixel points p on an outer contour line of the first subregion and Δp′of corresponding pixel points p′ on an outer contour line of thecorresponding second subregion, Δp is an angle between a radialdirection and a gradient direction of each pixel point p, and Δp′ is anangle between a radial direction and a gradient direction of each pixelpoint p′; and calculating a principal rotation direction α of thedetection image according to the principal rotation directions of theplurality of first subregions of the detection image.
 2. The imageprocessing method according claim 1, wherein the calculating theprincipal rotation direction α of the detection image according to theprincipal rotation directions of the plurality of first subregions ofthe detection image comprises: step S1 of setting i=1; step S2 ofcomparing α_(i) with α_(i+1), and adjusting the principal rotationdirection of the detection image using an equation:$\alpha = {\arctan \; {\quad\left( \frac{\sum\limits_{u = 1}^{u = {i + 1}}{\sin \; \alpha_{u}}}{\sum\limits_{u = 1}^{u = {i + 1}}{\cos \; \alpha_{u}}} \right)}}$in the case that |α_(i)−α_(i+1)|≤ω, wherein u≤n, u is a positiveinteger, and α_(i) represents the principal rotation direction of ani^(th) first subregion of the plurality of first subregions; step S3 ofassigning i=i+1; and in the case that i is less than n, repeating stepsS2 and S3, wherein n represents the number of the plurality of firstsubregions.
 3. The image processing method according claim 2, whereinbefore the step S1, the image processing method further comprises:sorting the principal rotation directions of the plurality of firstsubregions such that α_(i)>α_(i+1).
 4. The image processing methodaccording claim 2, wherein ω=45°.
 5. The image processing methodaccording claim 1, wherein before the step of calculating a principalrotation direction of each of the plurality of first subregions withrespect to corresponding second subregion, the image processing methodfurther comprises: selecting a circular region with one pixel point p onan outer contour line of each of the first subregions as a center of thecircular region, dividing the circular region into v concentric circleswith the pixel point p as a center of the circles, and equally dividingthe circular region into w sector regions with the pixel point p as avertex of the sector regions, to obtain v*w third subregions, wherein vand w are positive integers greater than or equal to 2; calculating asum θ of gradient directions of all the pixel points in each of thethird subregions; and calculating a gradient direction θ_(p) of thepixel point p, wherein θ_(p) is a sum of products of θ of all the thirdsubregions and corresponding assigned weights ε, and ε is directlyproportional to a distance between a central point of the thirdsubregion and the pixel point p.
 6. The image processing methodaccording claim 5, wherein the dividing the circular region into vconcentric circles with the pixel point p as a center of the circles,and equally dividing the circular region into w sector regions with thepixel point p as a vertex of the sector regions, to obtain v*w thirdsubregions comprises: dividing the circular region into two concentriccircles with the pixel point p as the center of the circles, anddividing the circular region into 8 sector regions with the pixel pointp as the vertex of the sector regions, to obtain 16 third subregions. 7.The image processing method according claim 5, wherein before the stepof calculating a principal rotation direction of each of the pluralityof first subregions with respect to corresponding second subregion, theimage processing method further comprises: selecting a circular regionwith one pixel point p′ on an outer contour line of each of the secondsubregions as a center of the circular region, dividing the circularregion into v concentric circles with the pixel point p′ as a center ofthe circles, and equally dividing the circular region into w sectorregions with the pixel point p′ as a vertex of the sector regions, toobtain v*w fourth subregions; calculating a sum θ′ of gradientdirections of all the pixel points in each of the fourth subregions; andcalculating a gradient direction θ_(p)′ of the pixel point p′, whereinθ_(p)′ is a sum of products of θ′ of all the fourth subregions andcorresponding assigned weights ε′, ε′ is directly proportional to adistance between a central point of the fourth subregion and the pixelpoint p′, and v and w are positive integers greater than or equal to 2.8. The image processing method according claim 1, wherein: the detectionimage is a circular region; the dividing the detection image into aplurality of first subregions comprises: defining a region where adistance from the center of the detection image is less than r_(i) andgreater than r_(i−1) as the i^(th) first subregion of the plurality offirst subregions, wherein r_(i−1)<r_(i), r₀=0, i is a positive integerand runs from 1 to n, and n represents the number of the firstsubregions; the dividing the template image into a plurality of secondsubregions comprises: defining a region where a distance from the centerof the template image is less than r_(i) and greater than r_(i−1) as thei^(th) second subregion of the plurality of second subregions, whereinr_(i−1)<r_(i), r₀≥0, i is a positive integer and runs from 1 to n, and nrepresents the number of the second subregions; and the calculating aprincipal rotation direction of each of the plurality of firstsubregions of the detection image with respect to corresponding secondsubregion comprises: determining the principal rotation direction of thedetection image with a radius of r_(i) with respect to the templateimage with a radius of r_(i) as the principal rotation direction α_(i)of the i^(th) first subregion with respect to the corresponding secondsubregion.
 9. The image processing method according claim 8, whereinbefore the step of calculating a principal rotation direction of each ofthe plurality of first subregions with respect to corresponding secondsubregion, the image processing method further comprises: establishing acoordinate system with a center of the detection image as an origin; andcalculating a radial direction φ_(p) of one pixel point p on an outercontour line of each of the first subregions using an equation${\phi_{p} = {\arctan \; \frac{\Delta \; p_{y}}{\Delta \; p_{x}}}},$wherein (Δp_(x), Δp_(y)) is coordinates of the pixel point p, and0≤φ_(p)<2π.
 10. The image processing method according claim 8, whereinbefore the step of calculating a principal rotation direction of each ofthe plurality of first subregions with respect to corresponding secondsubregion, the image processing method further comprises: establishing acoordinate system with a center of the template image as an origin; andcalculating a radial direction φ_(p)′ of one pixel point p′ on an outercontour line of each of the second subregions using an equation${\phi_{p}^{\prime} = {\arctan \; \frac{\Delta \; p_{y}^{\prime}}{\Delta \; p_{x}^{\prime}}}},$wherein (Δp_(x)′, Δp_(y)′) is coordinates of the pixel point p′, and0≤φ_(p)′<2π.
 11. An image processing device, comprising: a processor anda memory, wherein the processor is configured to execute a programstored in the memory, so as to: divide a detection image into aplurality of first subregions, and divide a template image into aplurality of second subregions, wherein a center of each of theplurality of first subregions coincides with a center of the detectionimage, a center of each of the plurality of second subregions coincideswith a center of the template image, and the plurality of firstsubregions is in one-to-one correspondence to the plurality of secondsubregions; calculate a principal rotation direction of each of theplurality of first subregions with respect to corresponding secondsubregion, wherein the principal rotation direction of the firstsubregion with respect to the corresponding second subregion is anaverage value of sums of difference values of Δp of all pixel points pon an outer contour line of the first subregion and Δp′ of correspondingpixel points p′ on an outer contour line of the corresponding secondsubregion, Δp is an angle between a radial direction and a gradientdirection of each pixel point p, and Δp′ is an angle between a radialdirection and a gradient direction of each pixel point p′; and calculatea principal rotation direction α of the detection image according to theprincipal rotation directions of the plurality of first subregions ofthe detection image.
 12. The image processing device according claim 11,wherein the processor is further configured to execute following steps:step S1 of setting i=1; step S2 of comparing α_(i) with α_(i+1), andadjusting the principal rotation direction of the detection image usingan equation:$\alpha = {\arctan \; {\quad\left( \frac{\sum\limits_{u = 1}^{u = {i + 1}}{\sin \; \alpha_{u}}}{\sum\limits_{u = 1}^{u = {i + 1}}{\cos \; \alpha_{u}}} \right)}}$in the case that |α_(i)−α_(i+1)|≤ω, wherein u≤n, u is a positiveinteger, and α_(i) represents the principal rotation direction of ani^(th) first subregion of the plurality of first subregions; step S3 ofassigning i=i+1; and in the case that i is less than n, repeating stepsS2 and S3, wherein n represents the number of the plurality of firstsubregions.
 13. The image processing device according claim 12, whereinthe processor is further configured to, before the step S1, sort theprincipal rotation directions of the plurality of first subregions suchthat α_(i)>α_(i+1).
 14. The image processing device according claim 12,wherein ω=45°.
 15. The image processing device according claim 11,wherein the processor is further configured to: select a circular regionwith one pixel point p on an outer contour line of each of the firstsubregions as a center of the circular region, divide the circularregion into v concentric circles with the pixel point p as a center ofthe circles, and equally divide the circular region into w sectorregions with the pixel point p as a vertex of the sector regions, toobtain v*w third subregions, wherein v and w are positive integersgreater than or equal to 2; calculate a sum θ of gradient directions ofall the pixel points in each of the third subregions; and calculate agradient direction θ_(p) of the pixel point p, wherein θ_(p) is a sum ofproducts of θ of all the third subregions and corresponding assignedweights c, and c is directly proportional to a distance between acentral point of the third subregion and the pixel point p.
 16. Theimage processing device according claim 15, wherein the processor isfurther configured to divide the circular region into two concentriccircles with the pixel point p as the center of the circles, and dividethe circular region into 8 sector regions with the pixel point p as thevertex of the sector regions, to obtain 16 third subregions.
 17. Theimage processing device according claim 15, wherein the processor isfurther configured to: select a circular region with one pixel point p′on an outer contour line of each of the second subregions as a center ofthe circular region, divide the circular region into v concentriccircles with the pixel point p′ as a center of the circles, and equallydivide the circular region into w sector regions with the pixel point p′as a vertex of the sector regions, to obtain v*w fourth subregions;calculate a sum θ′ of gradient directions of all the pixel points ineach of the fourth subregions; and calculate a gradient direction θ_(p)′of the pixel point p′, wherein θ_(p)′ is a sum of products of θ′ of allthe fourth subregions and respective corresponding assigned weights ε′,ε′ is directly proportional to a distance between a central point of thefourth subregion and the pixel point p′, and v and w are positiveintegers greater than or equal to
 2. 18. The image processing deviceaccording claim 11, wherein the detection image is a circular region,and the processor is further configured to: define a region where adistance from the center of the detection image is less than r_(i) andgreater than r_(i−1) as the i^(th) first subregion of the plurality offirst subregions, wherein r_(i−1)<r_(i), r₀=0, i is a positive integerand runs from 1 to n, and n represents the number of the firstsubregions; define a region where a distance from the center of thetemplate image is less than r_(i) and greater than r_(i−1) as the i^(th)second subregion of the plurality of second subregions, whereinr_(i−1)<r_(i), r₀≥0, i is a positive integer and runs from 1 to n, and nrepresents the number of the second subregions; and determine theprincipal rotation direction of the detection image with a radius ofr_(i) with respect to the template image with a radius of r_(i) as theprincipal rotation direction α_(i) of the i^(th) first subregion withrespect to the corresponding second subregion.
 19. The image processingdevice according claim 18, wherein the processor is further configuredto: establish a coordinate system with a center of the detection imageas an origin; and calculate a radial direction of one pixel point p onan outer contour line of each of the first subregions using an equation${\phi_{p} = {\arctan \; \frac{\Delta \; p_{y}}{\Delta \; p_{x}}}},$wherein (Δp_(x), Δp_(y)) is coordinates of the pixel point p, and0≤φ_(p)<2π.
 20. The image processing device according claim 18, whereinthe processor is further configured to: establish a coordinate systemwith a center of the template image as an origin; and calculate a radialdirection of one pixel point p′ on an outer contour line of each of thesecond subregions to using an equation${\phi_{p}^{\prime} = {\arctan \; \frac{\Delta \; p_{y}^{\prime}}{\Delta \; p_{x}^{\prime}}}},$wherein (Δp_(x)′, Δp_(y)′) is coordinates of the pixel point p′, and0≤φ_(p)′<2π.